package com.hardroid.workload.ui.fragment;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;

import com.hardroid.workload.R;
import com.hardroid.workload.utils.Singleton;

public class EditNoteFragment extends Fragment{

	private EditText noteEdit;
	private Button cancelButton;
	private Button saveButton;

	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		return inflater.inflate(R.layout.fragment_edit_note, container,false);
	}
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onActivityCreated(savedInstanceState);
		

		noteEdit = (EditText) getView().findViewById(R.id.edit_note_edit_text);
		cancelButton = (Button) getView().findViewById(R.id.edit_note_cancel_button);
		saveButton = (Button) getView().findViewById(R.id.edit_note_save_button);

			
		cancelButton.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				getActivity().finish();
			}
		});
		saveButton.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (Singleton.currentProject != null) {
					Singleton.currentProject.projectNotes = noteEdit.getText()
							.toString();
					Singleton.saveProject(Singleton.currentProject);
				}
				getActivity().finish();
			}
		});
	}
	
	@Override
	public void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		super.onResume();
		if (Singleton.currentProject != null) {
			if (Singleton.currentProject.projectNotes != null) {
				noteEdit.setText(Singleton.currentProject.projectNotes);
			}
		}	
	}
	
}
